package com.springframework.beans.factory.annotation;

import com.springframework.beans.factory.support.MyGenericBeanDefinition;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
 * @Author 虎哥
 * @Description @Component 以及派生注解定义 Bean
 * 多了一个 AnnotationMetadata 注解类元信息对象，例如通过 @Component 注解定义的 Bean 会解析成该对象
 * <p>
 * 要带着问题去学习,多猜想多验证
 **/
public class MyScannedGenericBeanDefinition extends MyGenericBeanDefinition implements MyAnnotatedBeanDefinition {
    private final AnnotationMetadata metadata;

    public MyScannedGenericBeanDefinition(MetadataReader metadataReader) {
        Assert.notNull(metadataReader, "MetadataReader must not be null");
        this.metadata = metadataReader.getAnnotationMetadata();
        setBeanClassName(this.metadata.getClassName());
    }

    @Override
    public final AnnotationMetadata getMetadata() {
        return this.metadata;
    }

    @Override
    @Nullable
    public MethodMetadata getFactoryMethodMetadata() {
        return null;
    }

    @Override
    public int getRole() {
        return 0;
    }

    @Override
    public boolean isPrimary() {
        return false;
    }

    @Override
    public boolean isAutowireCandidate() {
        return false;
    }
}
